package com.bjpowernode.controllers;

import com.bjpowernode.entities.TTran;
import com.bjpowernode.querys.TranQuery;
import com.bjpowernode.result.Result;
import com.bjpowernode.services.TranService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
public class TranController {
    @Resource
    private TranService tranService;

    @GetMapping(value = "/api/tran/{id}")
    public Result getTranById(@PathVariable(value = "id") Integer id) {
        TTran tTran = tranService.getTranById(id);
        return Result.OK(tTran);
    }

    @GetMapping(value = "/api/trans")
    public Result getTransByPage(@RequestParam(value = "current", required = false, defaultValue = "1") Integer current) {
        PageInfo<TTran> pageInfo = tranService.getTransByPage(current);
        return Result.OK(pageInfo);
    }

    @PostMapping(value = "/api/tran")
    public Result addTran(@RequestBody TranQuery tranQuery) {
        int create = tranService.addTran(tranQuery);
        return create >= 1 ? Result.OK() : Result.FAIL();
    }
}
